import {
  configureStore,
  createSlice
} from '@reduxjs/toolkit';

const themeSlice = createSlice({
  name: 'theme',
  initialState: {
    isDark: false,
    version:'1.0.4'
  },
  reducers: {
    toggleTheme: (state) => {
      localStorage.setItem('theme', !state.isDark);
      state.isDark = !state.isDark;
    },
    initTheme: (state) => {
      if (localStorage.getItem('theme') != undefined) {
        state.isDark = localStorage.getItem('theme') == "true";
      } else {
        state.isDark = false;
      }
    }
  }
});

// 创建 store
export const store = configureStore({
  reducer: {
    theme: themeSlice.reducer
  }
});

// 导出 action
export const {
  toggleTheme,
  initTheme
} = themeSlice.actions;